package rgil.pojo;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
public class Compromisso implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id 
	@SequenceGenerator(name="generator", sequenceName="compromisso_id_seq")
	@GeneratedValue(generator="generator", strategy=GenerationType.AUTO)
	private int idCompromisso;
	
	@ManyToOne
	@JoinColumn(name="id_cliente")
	private Cliente cliente;
	
	@ManyToOne
	@JoinColumn(name="id_usuario_criou")
	private Usuario usuarioCriou;
	
	@ManyToOne
	@JoinColumn(name="id_usuario_responsavel")
	private Usuario usuarioResponsavel;
	
	@Column(nullable=false)
	@Enumerated(EnumType.ORDINAL)
	private Tipo tipo;
	
	@Column
	private String descricao;
	
	@Column(nullable=false, name="data_criacao")
	@Temporal(TemporalType.TIMESTAMP)
	private Date dataCriacao;
	
	@Column(name="data_conclusao")
	@Temporal(TemporalType.TIMESTAMP)
	private Date dataConclusao;
	
	@Column(name="data_compromisso")
	@Temporal(TemporalType.DATE)
	private Date dataCompromisso;
	
	@Column(nullable=false, name="hora_compromisso")
	@Temporal(TemporalType.TIME)
	private Date horaCompromisso;
	
	@Column(nullable=false)
	@Enumerated(EnumType.ORDINAL)
	private Status status;
	
	public int getIdCompromisso() {
		return idCompromisso;
	}
	public void setIdCompromisso(int idCompromisso) {
		this.idCompromisso = idCompromisso;
	}
	public Cliente getCliente() {
		return cliente;
	}
	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}
	public Usuario getUsuarioCriou() {
		return usuarioCriou;
	}
	public void setUsuarioCriou(Usuario usuarioCriou) {
		this.usuarioCriou = usuarioCriou;
	}
	public Usuario getUsuarioResponsavel() {
		return usuarioResponsavel;
	}
	public void setUsuarioResponsavel(Usuario usuarioResponsavel) {
		this.usuarioResponsavel = usuarioResponsavel;
	}
	public Tipo getTipo() {
		return tipo;
	}
	public void setTipo(Tipo tipo) {
		this.tipo = tipo;
	}
	public String getDescricao() {
		return descricao;
	}
	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}
	public Date getDataCriacao() {
		return dataCriacao;
	}
	public void setDataCriacao(Date dataCriacao) {
		this.dataCriacao = dataCriacao;
	}
	public Date getDataConclusao() {
		return dataConclusao;
	}
	public void setDataConclusao(Date dataConclusao) {
		this.dataConclusao = dataConclusao;
	}
	public Date getDataCompromisso() {
		return dataCompromisso;
	}
	public void setDataCompromisso(Date dataCompromisso) {
		this.dataCompromisso = dataCompromisso;
	}
	public Date getHoraCompromisso() {
		return horaCompromisso;
	}
	public void setHoraCompromisso(Date horaCompromisso) {
		this.horaCompromisso = horaCompromisso;
	}
	public Status getStatus() {
		return status;
	}
	public void setStatus(Status status) {
		this.status = status;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((cliente == null) ? 0 : cliente.hashCode());
		result = prime * result
				+ ((dataCompromisso == null) ? 0 : dataCompromisso.hashCode());
		result = prime * result
				+ ((horaCompromisso == null) ? 0 : horaCompromisso.hashCode());
		result = prime * result + ((tipo == null) ? 0 : tipo.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Compromisso other = (Compromisso) obj;
		if (cliente == null) {
			if (other.cliente != null)
				return false;
		} else if (!cliente.equals(other.cliente))
			return false;
		if (dataCompromisso == null) {
			if (other.dataCompromisso != null)
				return false;
		} else if (!dataCompromisso.equals(other.dataCompromisso))
			return false;
		if (horaCompromisso == null) {
			if (other.horaCompromisso != null)
				return false;
		} else if (!horaCompromisso.equals(other.horaCompromisso))
			return false;
		if (tipo != other.tipo)
			return false;
		return true;
	}
	
	
}
